import Http, {ReqProps} from "@/common/http";
import {BaseEntitys} from "@/common/httptypes";

// 现有结构-//后期需整改数据-没用的删掉
export type SysMenuTree = {
    children: SysMenuTree[]
    id: number
    menuName: string
    type: string
    code?: string
    del?: string
    icon?: string
    parentId?: number
    path?: string
    sort?: string
    status?: string
    styleCss?: string
} & BaseEntitys


// 转化结构
export type SysMenuTreePlus = {
    code: string
    parentId: string
    key: string
    title: string
    type: string
    path: string
    icon: string
    sort: string
    children: SysMenuTreePlus[]
}


// 转化函数
export function arrIndex(arr: any, data: any) {
    for (let i in data) {
      let item = data[i];
      // eslint-disable-next-line @typescript-eslint/no-array-constructor
      let children = new Array();
      if (item.children && item.children.length > 0) {
        arrIndex(children, item.children);
      }
      arr.push({
        key: item.id,
        parentId: item.parentId,
        code: item.code,
        title: item.menuName,
        type: item.type,
        path: item.path,
        icon: item.icon,
        sort: item.sort,
        children: children,
      });
    }
    return arr
  }

  

class SysMenu {
    RowKey = "id"
    EDIT = "menuManagementEdit"
    ADD = "menuManagementAdd"
    DEL = "menuManagementDelete"
    MAPPING = {menuManagementEdit: "编辑菜单", menuManagementAdd: "新增菜单"}



    selectTree(props: ReqProps<SysMenuTree[]>) {
        Http.doGet("/menu/getTree", props)
    }
    selectView(props: ReqProps<[]>) {
        Http.doGet("/menu/getTree", props)
    }

    doSave(props: ReqProps<void>) {
        Http.doPost("/menu/save", props)
    }

    doEdit(props: ReqProps<void>) {
        Http.doPost("/menu/updateById", props)
    }

    selectById(props: ReqProps<void>) {
        Http.doGet("/menu/getById", props)
    }

    delete(props: ReqProps<void>) {
        Http.doDelete("/menu/deleteById", props)
    }

}

// eslint-disable-next-line import/no-anonymous-default-export
export default new SysMenu()